<template>
  <div class="SubjectsAdd-container">
    <el-form label-width="100px" class="demo-ruleForm"
      ><el-form-item label="学科名称" placeholder="请输出学科名称">
        <el-input v-model="Body.subjectName"></el-input>
      </el-form-item>
      <el-form-item label="是否显示">
        <el-switch
          :active-value="1"
          :inactive-value="0"
          v-model="Body.isFrontDisplay"
        ></el-switch>
      </el-form-item>
      <el-form-item
        ><el-button @click="$emit('close-addSubject')">取消</el-button>
        <el-button type="primary" @click="AddSubject()">确认</el-button>
      </el-form-item></el-form
    >
  </div>
</template>

<script>
import { add } from "@/api/hmmm/subjects.js";
export default {
  name: "SubjectsAdd",
  data() {
    return {
      subjectName: "", //新增学科名称
      isFrontDisplay: true, //新增学科是否显示
      // isFrontDisplay: 1,
      Body: {
        subjectName: "",
        isFrontDisplay: 1,
      },
    };
  },
  methods: {
    // 添加学科
    async AddSubject() {
      console.log(this.Body);
      try {
        const { data } = await add(this.Body);
        console.log(data);
        this.$message.success("添加成功！");
        this.$emit("add-success");
        this.Body.subjectName = "";
      } catch (error) {
        this.$message.error("添加失败！");
      }
    },
  },
};
</script>

<style scoped lang='less'>
/deep/ .el-form-item__content {
  margin-left: 310px;
}
</style>
